//
//  GzVC+UI.swift
//  Auscultation
//
//  Created by 来 on 2020/12/8.
//

import Foundation

extension GzVC {
    
    func initUI() {
        
        let top_view = UIImageView()
        top_view.image = UIImage(named: "table2")

        top_view.isUserInteractionEnabled = true
        view.addSubview(top_view)
        top_view.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(100)
        }
        
        let label1 = UILabel.init()
        label1.text = "工作"
        label1.textColor = UIColor.white
        label1.font = UIFont.boldSystemFont(ofSize: 30)
        top_view.addSubview(label1)
        label1.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20)
            make.centerY.equalToSuperview().multipliedBy(1.0).offset((UIDevice.lgf_NavBarH() - 44) / 2)
        }
        
        let image_view2_b = UIView.init()
        image_view2_b.lgf_AddTap(target: self, action: #selector(GzVC.s_xx(_:)))
        top_view.addSubview(image_view2_b)
        image_view2_b.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview().multipliedBy(1.0).offset((UIDevice.lgf_NavBarH() - 44) / 2)
            make.right.equalToSuperview().offset(-5)
            make.width.height.equalTo(50)
        }
        let image_view2 = UIImageView.init(image: #imageLiteral(resourceName: "xiaoxi@1.5x"))
        image_view2_b.addSubview(image_view2)
        image_view2.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(17)
            make.height.equalTo(20)
        }
        
        let msg_num_b = UIView.init()
        msg_num_b.isHidden = true
        msg_num_b.clipsToBounds = true
        msg_num_b.backgroundColor = UIColor.red
        msg_num_b.layer.cornerRadius = 8
        image_view2_b.addSubview(msg_num_b)
        msg_num_b.snp.makeConstraints { (make) in
            make.centerY.equalTo(image_view2).multipliedBy(0.6)
            make.centerX.equalTo(image_view2).multipliedBy(1.3)
            make.height.equalTo(16)
            make.width.greaterThanOrEqualTo(16)
        }
        msg_num = UILabel.init()
        msg_num.textAlignment = .center
        msg_num.font = UIFont.boldSystemFont(ofSize: 10)
        msg_num.textColor = UIColor.white
        msg_num_b.addSubview(msg_num)
        msg_num.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalToSuperview().offset(-10)
        }
        
        let scrollView = UIScrollView.lgf_Table("FFFFFF")
        if #available(iOS 11.0, *) {
            scrollView.contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.top.equalTo(top_view.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        var menuList = EWEUser.lgf.menuList.lgf_ToDictionaryArray()
        menuList = menuList.filter({ (dict) -> Bool in
            let display = (dict["display"] as? Int) ?? 0
            return display == 1
        })
        for (i, dict) in menuList.enumerated() {
            let showOrder = i + 1
            let title = (dict["title"] as? String) ?? ""
            
            let menu = UIImageView.init()
            menu.isUserInteractionEnabled = true
            var stitle: String = ""
            if title == "标注包" {
                menu.image = UIImage(named: "gzbg1")
                stitle = "Label package"
                menu.lgf_AddTap(target: self, action: #selector(s_bzb(_:)))
            } else if title == "审核包" {
                menu.image = UIImage(named: "gzbg2")
                stitle = "Audit package"
                menu.lgf_AddTap(target: self, action: #selector(s_shb(_:)))
            } else if title == "审核工作台" {
                menu.image = UIImage(named: "gzbg3")
                stitle = "Audit task list"
                menu.lgf_AddTap(target: self, action: #selector(s_shrwlb(_:)))
            } else if title == "标注工作台" {
                menu.image = UIImage(named: "gzbg4")
                stitle = "Label task list"
                menu.lgf_AddTap(target: self, action: #selector(s_bzrwlb(_:)))
            } else if title == "我的心音样本" {
                menu.image = UIImage(named: "gzbg5")
                stitle = "Sample"
                menu.lgf_AddTap(target: self, action: #selector(s_wdxyyb(_:)))
            } else if title == "样本仲裁" {
                menu.image = UIImage(named: "gzbg6")
                stitle = "Arbitration"
                menu.lgf_AddTap(target: self, action: #selector(s_ybzc(_:)))
            }
            scrollView.addSubview(menu)
            menu.snp.makeConstraints { (make) in
                let top = (Double(view.lgf_Width / 2 - 30) * (ceil(Double(showOrder) / 2.0) - 1)) + (ceil(Double(showOrder) / 2.0) * 20)
                make.top.equalTo(top)
                make.left.equalTo(showOrder % 2 == 0 ? (view.lgf_Width / 2 + 10) : 20)
                make.width.equalToSuperview().multipliedBy(0.5).offset(-30)
                make.height.equalTo(view.lgf_Width / 2 - 30)
            }
            
            let menu_label1 = UILabel.init()
            menu_label1.text = title
            menu_label1.font = UIFont.systemFont(ofSize: 18)
            menu_label1.textColor = UIColor.white
            menu.addSubview(menu_label1)
            menu_label1.snp.makeConstraints { (make) in
                make.centerY.equalToSuperview().multipliedBy(0.5)
                make.left.equalToSuperview().offset(20)
            }
            
            let menu_label2 = UILabel.init()
            menu_label2.text = stitle
            menu_label2.font = UIFont.systemFont(ofSize: 14)
            menu_label2.textColor = UIColor.white
            menu.addSubview(menu_label2)
            menu_label2.snp.makeConstraints { (make) in
                make.top.equalTo(menu_label1.snp.bottom).offset(5)
                make.left.equalToSuperview().offset(20)
            }
        }
        
        scrollView.lgf_AutoContentSize(20)
    }
    
}
